﻿using Mozi.HttpEmbedded;

namespace Mozi.Live.RTSP
{
    /// <summary>
    /// RTSP传输协议
    /// </summary>
    public class RTSPTransportProtocol
    {
        /// <summary>
        /// RTP/AVP
        /// </summary>
        public static readonly ProtocolVersion AVP = new ProtocolVersion("RTP", "AVP");
        /// <summary>
        /// RTP/AVP/UDP
        /// </summary>
        public static readonly ProtocolVersion AVPUDP = new ProtocolVersion("RTP", "AVP/UDP");
        /// <summary>
        /// RTP/AVPF
        /// </summary>
        public static readonly ProtocolVersion AVPF = new ProtocolVersion("RTP", "AVPF");
        /// <summary>
        /// RTP/AVPF/UDP
        /// </summary>
        public static readonly ProtocolVersion AVPFUDP = new ProtocolVersion("RTP", "AVPF/UDP");
        /// <summary>
        /// RTP/SAVP
        /// </summary>
        public static readonly ProtocolVersion SAVP = new ProtocolVersion("RTP", "SAVP");
        /// <summary>
        /// RTP/SAVP/UDP
        /// </summary>
        public static readonly ProtocolVersion SAVPUDP = new ProtocolVersion("RTP", "SAVP/UDP");
        /// <summary>
        /// RTP/SAVPF
        /// </summary>
        public static readonly ProtocolVersion SAVPF = new ProtocolVersion("RTP", "SAVPF");
        /// <summary>
        /// RTP/SAVPF/UDP
        /// </summary>
        public static readonly ProtocolVersion SAVPFUDP = new ProtocolVersion("RTP", "SAVPF/UDP");
        /// <summary>
        /// RTP/AVP/TCP
        /// </summary>
        public static readonly ProtocolVersion AVPTCP = new ProtocolVersion("RTP", "AVP/TCP");
        /// <summary>
        /// RTP/AVPF/TCP
        /// </summary>
        public static readonly ProtocolVersion AVPFTCP = new ProtocolVersion("RTP", "AVPF/TCP");
        /// <summary>
        /// RTP/SAVP/TCP
        /// </summary>
        public static readonly ProtocolVersion SAVPTCP = new ProtocolVersion("RTP", "SAVP/TCP");
        /// <summary>
        /// RTP/SAVPF/TCP
        /// </summary>
        public static readonly ProtocolVersion SAVPFTCP = new ProtocolVersion("RTP", "SAVPF/TCP");

        /// <summary>
        /// 解析协议
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ProtocolVersion Parse(string data)
        {
            if (data == AVP.ToString())
            {
                return AVP;

            }else if(data==AVPUDP.ToString()){
                return AVPUDP;
            }
            else if (data == AVPF.ToString())
            {
                return AVPF;
            }
            else if (data == AVPFUDP.ToString())
            {
                return AVPFUDP;
            }
            else if (data == SAVP.ToString())
            {
                return SAVP;
            }
            else if (data == SAVPUDP.ToString())
            {
                return SAVPUDP;
            }
            else if (data == SAVPF.ToString())
            {
                return SAVPF;
            }
            else if (data == SAVPFUDP.ToString())
            {
                return SAVPFUDP;
            }
            else if (data == AVPTCP.ToString())
            {
                return AVPTCP;
            }
            else if (data == AVPFTCP.ToString())
            {
                return AVPFTCP;
            }
            else if (data == SAVPTCP.ToString())
            {
                return SAVPTCP;
            }
            else if (data == SAVPFTCP.ToString())
            {
                return SAVPFTCP;
            }
            else
            {
                return new ProtocolVersion(data.Substring(0, data.IndexOf("/")), data.Substring(0, data.IndexOf("/") + 1));
            }
            
        }

        public static bool IsTCP(ProtocolVersion version)
        {
            return version == AVPTCP || version == AVPFTCP || version == SAVPTCP || version == SAVPFTCP;
        }
    }
}
